﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#include "LineEditDefinition.h"
#include "LineEditDefinitionReference.h"
#include "ILineEditHandler.h"
#include "ValidatorBase.h"
#include "EnableCompileWarning_The_LAST_IncludeInCpp.h"

using namespace gcmp;

gcmp::LineEditDefinitionReference::LineEditDefinitionReference(LineEditDefinition* pLineEditDefinition)
    : m_pControlDefinition(pLineEditDefinition)
{

}

gcmp::LineEditDefinitionReference::~LineEditDefinitionReference()
{

}

gcmp::LineEditInputType gcmp::LineEditDefinitionReference::GetInputType() const
{
    DBG_WARN_AND_RETURN_UNLESS(m_pControlDefinition, LineEditInputType::InputString, L"m_pControlDefinition为空",L"GDMPLab",L"2024-03-30");
    return m_pControlDefinition->GetInputType();
}

std::wstring gcmp::LineEditDefinitionReference::GetText() const
{
    DBG_WARN_AND_RETURN_UNLESS(m_pControlDefinition, L"", L"m_pControlDefinition为空",L"GDMPLab",L"2024-03-30");
    return m_pControlDefinition->GetText();
}

bool gcmp::LineEditDefinitionReference::SetText(const std::wstring& text)
{

    DBG_WARN_AND_RETURN_UNLESS(m_pControlDefinition, false, L"m_pControlDefinition为空",L"GDMPLab",L"2024-03-30");
    return m_pControlDefinition->SetText(text);
}

bool gcmp::LineEditDefinitionReference::IsEditing() const
{
    DBG_WARN_AND_RETURN_UNLESS(m_pControlDefinition, false, L"m_pControlDefinition为空",L"GDMPLab",L"2024-03-30");
    return m_pControlDefinition->IsEditing();
}

bool gcmp::LineEditDefinitionReference::SetIsEditing(bool isEditing)
{
    DBG_WARN_AND_RETURN_UNLESS(m_pControlDefinition, false, L"m_pControlDefinition为空",L"GDMPLab",L"2024-03-30");
    return m_pControlDefinition->SetIsEditing(isEditing);
}

gcmp::ILineEditEvent* gcmp::LineEditDefinitionReference::GetEvent() const
{
    DBG_WARN_AND_RETURN_UNLESS(m_pControlDefinition, nullptr, L"m_pControlDefinition为空",L"GDMPLab",L"2024-03-30");
    return m_pControlDefinition->GetEvent();
}

void gcmp::LineEditDefinitionReference::SelectAll()
{
    DBG_WARN_AND_RETURN_VOID_UNLESS(m_pControlDefinition, L"m_pControlDefinition为空",L"GDMPLab",L"2024-03-30");
    return m_pControlDefinition->SelectAll();
}

void gcmp::LineEditDefinitionReference::Clear()
{
    DBG_WARN_AND_RETURN_VOID_UNLESS(m_pControlDefinition, L"m_pControlDefinition为空",L"GDMPLab",L"2024-03-30");
    return m_pControlDefinition->Clear();
}

std::wstring gcmp::LineEditDefinitionReference::GetSelectedText() const
{
    DBG_WARN_AND_RETURN_UNLESS(m_pControlDefinition, L"", L"m_pControlDefinition为空",L"GDMPLab",L"2024-03-30");
    return m_pControlDefinition->GetSelectedText();
}

gcmp::IControlDefinitionChangeEvent* gcmp::LineEditDefinitionReference::GetControlDefinitionChangeEvent() const
{
    //程序关闭，library里的控件定义销毁，可能比绑定定义的控件先销毁
    //控件析构函数调用该函数时，m_pControlDefinition为空是正常的
    if (m_pControlDefinition)
    {
        return m_pControlDefinition->GetControlDefinitionChangeEvent();
    }
    return nullptr;
}

bool gcmp::LineEditDefinitionReference::SetValidator(OwnerPtr<ValidatorBase> opValidator)
{
    m_pControlDefinition->SetValidator(TransferOwnership(opValidator));
    return true;
}

ValidatorBase * gcmp::LineEditDefinitionReference::GetValidator()
{
    return m_pControlDefinition->GetValidator();
}

int gcmp::LineEditDefinitionReference::GetDecimals() const
{
    DBG_WARN_AND_RETURN_UNLESS(m_pControlDefinition, -1, L"m_pControlDefinition为空",L"GDMPLab",L"2024-03-30");
    return m_pControlDefinition->GetDecimals();
}

int gcmp::LineEditDefinitionReference::GetSelectionStart() const
{
    DBG_WARN_AND_RETURN_UNLESS(m_pControlDefinition, -1, L"m_pControlDefinition为空",L"GDMPLab",L"2024-03-30");
    return m_pControlDefinition->GetSelectionStart();
}

void gcmp::LineEditDefinitionReference::SetSelection(int start, int length)
{
    DBG_WARN_AND_RETURN_VOID_UNLESS(m_pControlDefinition, L"m_pControlDefinition为空",L"GDMPLab",L"2024-03-30");
    return m_pControlDefinition->SetSelection(start, length);
}

std::wstring gcmp::LineEditDefinitionReference::GetId() const
{
    DBG_WARN_AND_RETURN_UNLESS(m_pControlDefinition, L"", L"m_pControlDefinition为空",L"GDMPLab",L"2024-03-30");
    return m_pControlDefinition->GetId();
}

std::wstring gcmp::LineEditDefinitionReference::GetCaption() const
{
    DBG_WARN_AND_RETURN_UNLESS(m_pControlDefinition, L"", L"m_pControlDefinition为空",L"GDMPLab",L"2024-03-30");
    return m_pControlDefinition->GetCaption();
}

std::wstring gcmp::LineEditDefinitionReference::GetTooltip() const
{
    DBG_WARN_AND_RETURN_UNLESS(m_pControlDefinition, L"", L"m_pControlDefinition为空",L"GDMPLab",L"2024-03-30");
    return m_pControlDefinition->GetTooltip();
}

bool gcmp::LineEditDefinitionReference::IsVisible() const
{
    DBG_WARN_AND_RETURN_UNLESS(m_pControlDefinition, false, L"m_pControlDefinition为空",L"GDMPLab",L"2024-03-30");
    return m_pControlDefinition->IsVisible();
}

bool gcmp::LineEditDefinitionReference::IsEnabled() const
{
    DBG_WARN_AND_RETURN_UNLESS(m_pControlDefinition, false, L"m_pControlDefinition为空",L"GDMPLab",L"2024-03-30");
    return m_pControlDefinition->IsEnabled();
}

bool gcmp::LineEditDefinitionReference::SetEnabled(bool enabled)
{
    DBG_WARN_AND_RETURN_UNLESS(m_pControlDefinition, false, L"m_pControlDefinition为空",L"GDMPLab",L"2024-03-30");
    return m_pControlDefinition->SetEnabled(enabled);
}

bool gcmp::LineEditDefinitionReference::SetVisible(bool visible)
{
    DBG_WARN_AND_RETURN_UNLESS(m_pControlDefinition, false, L"m_pControlDefinition为空",L"GDMPLab",L"2024-03-30");
    return m_pControlDefinition->SetVisible(visible);
}

bool gcmp::LineEditDefinitionReference::SetControlHandler(OwnerPtr<ILineEditHandler> pControlHandler)
{
    DBG_WARN_AND_RETURN_UNLESS(m_pControlDefinition, false, L"m_pControlDefinition为空",L"GDMPLab",L"2024-03-30");
    return m_pControlDefinition->SetControlHandler(TransferOwnership(pControlHandler));
}

bool gcmp::LineEditDefinitionReference::BlockControlHandler(bool needBlock)
{
    return m_pControlDefinition->BlockControlHandler(needBlock);
}
